package com.tledu.zyf.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.tledu.zyf.model.User;
import com.tledu.zyf.service.impl.UserService;
import com.tledu.zyf.util.Pager;

@WebServlet("/user/pager")
public class UserPagerServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 页码
		int page = Integer.parseInt(request.getParameter("page"));
		// 每页显示的条数
		int limit = Integer.parseInt(request.getParameter("limit"));

		Pager<User> pager = new UserService().find(page, limit);
//		System.out.println("--------" + JSON.toJSON(pager));
		// toJSONString 会解析成 {"$ref":"$.data[3].group"}
		// 用 toJSON 才能解析成正确的格式
		response.getWriter().println(JSON.toJSON(pager));
	}
}
